import { GATEWAY_IP, PORT } from './address'
import httpRequest from '../utils/httpRequest'
/**
 * 获取分类列表
 * 
 * @returns 
 */
export const getLableList = () => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/label/list`,
            method : 'get',
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 获取单位列标
 * 
 * @returns 
 * 
 */
export const getUnitList = () => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/unit/list`,
            method : 'get',
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 
 * 保存商品
 * 
 * @param {*} data 
 * @returns 
 */
export const saveGoods = (data) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/goods/save`,
            method : 'post',
            data : data
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 根据ID获取商品
 * 
 * @param {*} id 
 * @returns 
 */
export const getGoodsById = (id) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/goods/${id}`,
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 获取最热商品
 * 
 * @returns 
 */
export const getHotGoods = () => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/goods/gethotgoods`,
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 获取最新商品
 * 
 * @returns 
 * 
 */
export const getNewGoods = () => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/goods/getnewgoods`,
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 获取商品列表
 * 
 * @param {*} data 
 * @returns 
 */
export const getGoodsList = (data) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/goods/list`,
            method : 'get',
            params : {
                page : data.page,
                keyWord: data.keyWord,
                labelIds: data.labelIds 
            }
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 获取用户（供应商）商品
 * 
 */
export const userGoodsList = (page) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/goods/usergoodslist/${page}`,
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 根据ID删除商品
 * 
 * @param {*} id 
 * @returns 
 */
export const deleteById = (id) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/goods/delete/${id}`,
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 商品详情处猜你喜欢
 * 
 * @param {*} id 
 * @returns 
 */
export const detailedGuessYouLike = (id) => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/goods/detailed/like/${id}`,
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
/**
 * 获取商品数量
 * 
 * @returns 
 */
export const getGoodsCount = () => {
    return new Promise((resolve,reject) => {
        httpRequest({
            url : `http://${GATEWAY_IP}:${PORT}/gateway/product/goods/count`,
            method : 'get'
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}